package com.wlr.study.leetcode;

/**
 * @author lerong.wang
 * @version 1.0.0
 * @description
 * @date 2024/12/16 17:34
 */
public class LeetCode28 {

    public int strStr(String haystack, String needle) {
        int i = 0, j = 0, temp = 0;
        while (j < needle.length() && i < haystack.length()) {
            if (haystack.charAt(i) == needle.charAt(j)) {
                i++;
                j++;
            } else {
                temp++;
                i = temp;
                j = 0;
            }
        }
        if (j == needle.length()) {
            return i - j;
        }
        return -1;
    }

    public static void main(String[] args) {
        LeetCode28 leetCode28 = new LeetCode28();
        System.out.println(leetCode28.strStr("mississippi", "issip"));
    }
}